package org.frend.rpc.impl;

import com.alibaba.dubbo.config.annotation.Service;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.frend.rpc.model.ProcessInstanceModel;
import org.frend.rpc.service.StartProcessInstanceService;
import org.springframework.beans.factory.annotation.Autowired;

@Service(timeout = 1200000)
public class StartProcessInstanceServiceImpl implements StartProcessInstanceService {

    @Autowired
    private RuntimeService runtimeService;

    @Override
    public ProcessInstanceModel startProcessInstanceByKey(String processDefinitionKey) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey);
        ProcessInstanceModel model = new ProcessInstanceModel();
        model.setBusinessKey(processInstance.getBusinessKey());
        model.setName(processInstance.getName());
        model.setProcessDefinitionId(processInstance.getProcessDefinitionId());
        model.setProcessVariables(processInstance.getProcessVariables());
        model.setSuspended(processInstance.isSuspended());
        model.setTenantId(processInstance.getTenantId());
        return model;
    }

}
